package com.bot.edu.applysystem.applycontract.service.impl;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeWapPayModel;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.bot.edu.applysystem.applycontract.entity.ApplyContract;
import com.bot.edu.applysystem.applycontract.mapper.ApplyContractMapper;
import com.bot.edu.applysystem.applycontract.service.IApplyContractService;
import com.bot.edu.utils.AlipayConfig;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 合同表
 * @Author: jeecg-boot
 * @Date:   2022-04-08
 * @Version: V1.0
 */
@Service
public class ApplyContractServiceImpl extends ServiceImpl<ApplyContractMapper, ApplyContract> implements IApplyContractService {

    @Override
    public String pay(ApplyContract contract) throws AlipayApiException {

        //获得初始化的AlipayClient
       // AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, "json", AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE);
        AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY,AlipayConfig.SIGNTYPE);
        AlipayTradeWapPayRequest alipay_request=new AlipayTradeWapPayRequest();


        AlipayTradeWapPayModel model=new AlipayTradeWapPayModel();
        model.setOutTradeNo(contract.getContractId());//id
        model.setSubject("课程费用");//订单名称
        model.setTotalAmount(contract.getContractMoney()+"");//支付金额
        model.setBody("课程费用");
        //model.setTimeoutExpress(date.toString());
        model.setProductCode("QUICK_WAP_WAY");
        alipay_request.setBizModel(model);
        alipay_request.setNotifyUrl(AlipayConfig.notify_url);
        // 设置同步地址
        alipay_request.setReturnUrl(AlipayConfig.return_url);
        // 调用SDK生成表单
        String  form = client.pageExecute(alipay_request).getBody();
        return form;
    }
}
